package com.santiao.publics.ui;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.TextView;

import com.santiao.youxiang.R;
import com.santiao.publics.callback.DialogCallBack;

import androidx.annotation.NonNull;



public class AgreementDialog extends Dialog implements View.OnClickListener {
    private DialogCallBack agreementCallBack;
    private TextView btn_go_home;
    private TextView tv_back, tv_user_protocol, tv_user_policy;

    public static void showDialog(Context context, DialogCallBack agreementCallBack) {
        AgreementDialog agreementDialog = new AgreementDialog(context, agreementCallBack);
        agreementDialog.showDialog();
    }


    public AgreementDialog(@NonNull Context context, DialogCallBack agreementCallBack) {
        super(context);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        this.agreementCallBack = agreementCallBack;
        initView(context);
    }

    private void initView(Context context) {
        View view = View.inflate(context, R.layout.public_dialog_wifi_privacy_agreement, null);
        setContentView(view);
        this.setCanceledOnTouchOutside(false);
        this.setCancelable(false);
        this.tv_user_protocol = view.findViewById(R.id.tv_user_protocol);
        this.tv_user_policy = view.findViewById(R.id.tv_user_policy);
        this.btn_go_home = view.findViewById(R.id.btn_go_home);
        this.tv_back = view.findViewById(R.id.tv_back);
        Animation anim = AnimationUtils.loadAnimation(context, R.anim.public_heartbeat);
        this.btn_go_home.startAnimation(anim);

        this.btn_go_home.setOnClickListener(this);
        this.tv_back.setOnClickListener(this);
        this.tv_user_protocol.setOnClickListener(this);
        this.tv_user_policy.setOnClickListener(this);

    }

    private void showDialog() {
        this.show();
    }

    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View v) {

            if (v.getId()==R.id.btn_go_home){

                    if (agreementCallBack != null) {
                        agreementCallBack.buAgree();
                    }
                    dismiss();
            }  else   if (v.getId()== R.id.tv_back){
                if (agreementCallBack != null) {
                    agreementCallBack.disagree();
                }
                dismiss();
             }
            else   if (v.getId()==  R.id.tv_user_protocol){
                WebViewActivity.gotoActivity(getContext(), "《用户协议》","yhxy");
             }
             else   if (v.getId()==  R.id.tv_user_policy){
                WebViewActivity.gotoActivity(getContext(), "《隐私政策》","ystk");
             }

    }
}
